import os
import sys
import shutil

def apply_patch():
    """应用 mobi_cover 补丁"""
    # 获取 mobi 库的安装路径
    import mobi
    mobi_path = os.path.dirname(mobi.__file__)
    
    # 目标文件路径
    target_file = os.path.join(mobi_path, 'mobi_cover.py')
    
    # 备份原始文件
    if os.path.exists(target_file):
        backup_file = target_file + '.bak'
        shutil.copy2(target_file, backup_file)
        print(f"已备份原始文件到: {backup_file}")
    
    # 复制补丁文件
    shutil.copy2('mobi_cover_patch.py', target_file)
    print(f"已应用补丁到: {target_file}")

if __name__ == "__main__":
    apply_patch() 